package top.jsjkxyjs.blackbox.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import top.jsjkxyjs.blackbox.common.listener.RequestListener;
import top.jsjkxyjs.blackbox.service.*;
import top.jsjkxyjs.blackbox.ws.EventDataEndPoint;
import top.jsjkxyjs.blackbox.ws.UserIotDataEndpoint;

@Configuration
public class WebSocketConfig {
	@Autowired
	private RequestListener requestListener;

	@Bean
	public ServerEndpointExporter serverEndpointExporter() {
		return new ServerEndpointExporter();
	}

	@Bean
	public ServletListenerRegistrationBean<RequestListener> servletListenerRegistrationBean() {
		ServletListenerRegistrationBean<RequestListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<>();
		servletListenerRegistrationBean.setListener(requestListener);
		return servletListenerRegistrationBean;
	}

	@Autowired
	private void setExcludeService(ExcludeService excludeService) {
		EventDataEndPoint.excludeService = excludeService;
	}

	@Autowired
	private void setUserService(UserService userService) {
		EventDataEndPoint.userService = userService;
	}

	@Autowired
	private void setDevBindService(DevBindService devBindService) {
		EventDataEndPoint.devBindService = devBindService;
	}

	@Autowired
	private void setEventService(EventService eventService) {
		EventDataEndPoint.eventService = eventService;
		UserIotDataEndpoint.eventService = eventService;
	}

	@Autowired
	private void setCarTypeService(CarTypeService carTypeService) {
		EventDataEndPoint.carTypeService = carTypeService;
	}

	@Autowired
	private void setIotService(IotService iotService) {

		UserIotDataEndpoint.iotService = iotService;
	}
}
